package algorithm.leetcode;

/**
 * @author SeonExlike
 * @since 2024/3/10
 */
public class NO80_删除有序数组中的重复项II {
    public static void main(String[] args) {
//        int[] nums = {1, 1, 1, 2, 2, 3};
        int[] nums = {0, 0, 1, 1, 1, 1, 2, 3, 3};
        int len = new Solution().removeDuplicates(nums);
        System.out.println(len);
        for (int i = 0; i < len; i++) {
            System.out.println(nums[i]);
        }
    }

    static class Solution {

        public int removeDuplicates(int[] nums) {
            if (nums.length <= 2) {
                return nums.length;
            }
            int index = 2;
            for (int i = 2; i < nums.length; i++) {
                if (nums[i] != nums[index - 2]) {
                    nums[index++] = nums[i];
                }
            }
            return index;
        }
    }
}
